from django.utils.deprecation import MiddlewareMixin
import time

class SetApiMiddleware(MiddlewareMixin):
    def process_request(self, request):
        request.start_time = time.time()

    def process_response(self,request, response):
        end_time = time.time() - request.start_time
        print(f'请求方法：{request.method},请求路径{request.path}')
        print(f'请求耗时{end_time}秒')
        return response